package com.whlilong.jxc.view;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import com.whlilong.jxc.constants.IAppConstants;
import com.whlilong.jxc.sys.CacheImage;
import com.whlilong.jxc.sys.IImageKey;
import com.whlilong.jxc.util.ViewerChange;

/**往来管理视图
 * @author sjy
 *
 */
public class ContactManagerView extends ViewPart implements ISelectionListener{

	public ContactManagerView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		createContent(parent);
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addSelectionListener(this);
	}

	private void createContent(Composite parent) {
		// TODO Auto-generated method stub
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 4;
		layout.marginTop = 10;
		layout.marginBottom = 10;
		layout.marginRight = 10;
		layout.marginLeft = 10;
		layout.makeColumnsEqualWidth = true;

		composite.setLayout(layout);
		composite.setBackgroundImage(CacheImage.getINSTANCE().getImage(
				IAppConstants.APPLICATION_ID, IImageKey.FUNCTIONS_BG));
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		if (!selection.isEmpty()) {
			IViewPart vp = getViewSite().getPage().findView(
					IAppConstants.systemManagerview_id);

			Table table = ((SystemManagerView) vp).getTableViewer().getTable();
			ViewerChange.getInstance().refreshView(table);
		}		
	}

}
